<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>小波的博客 | 小波的博客</title><meta name="author" content="Steve"><meta name="copyright" content="Steve"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="Lombok的使用(转载)我是莫提 我是莫提 8月17日   Lombok是什么东西？  Lombok 是一个很牛批的插件（本质是个 Java 库），项目里一旦引入了 Lombok 神器之后，只要程序中使用相关注解，那么你项目中所有诸如：对象的构造函数、 equals()方法，属性的 get()&#x2F;set() 方法等等，这些没有技术含量的代码统统都不用写了，Lombok 帮你搞定一切，全部帮你自动生">
<meta property="og:type" content="article">
<meta property="og:title" content="小波的博客">
<meta property="og:url" content="https://steve6636.gitee.io/2021/04/07/Lombok%20%E7%9A%84%E4%BD%BF%E7%94%A8_20210320/index.html">
<meta property="og:site_name" content="小波的博客">
<meta property="og:description" content="Lombok的使用(转载)我是莫提 我是莫提 8月17日   Lombok是什么东西？  Lombok 是一个很牛批的插件（本质是个 Java 库），项目里一旦引入了 Lombok 神器之后，只要程序中使用相关注解，那么你项目中所有诸如：对象的构造函数、 equals()方法，属性的 get()&#x2F;set() 方法等等，这些没有技术含量的代码统统都不用写了，Lombok 帮你搞定一切，全部帮你自动生">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg">
<meta property="article:published_time" content="2021-04-07T07:19:50.767Z">
<meta property="article:modified_time" content="2021-10-24T14:16:57.630Z">
<meta property="article:author" content="Steve">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://steve6636.gitee.io/2021/04/07/Lombok%20%E7%9A%84%E4%BD%BF%E7%94%A8_20210320/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = { 
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-10-24 22:16:57'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const fontSizeVal = saveToLocal.get('global-font-size')
    if (fontSizeVal !== undefined) {
      document.documentElement.style.setProperty('--global-font-size', fontSizeVal + 'px')
    }
    })(window)</script><meta name="generator" content="Hexo 5.4.0"><link rel="alternate" href="/atom.xml" title="小波的博客" type="application/atom+xml">
</head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="author-avatar"><img class="avatar-img" data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20210327175316.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">26</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">11</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 工具箱</span></a></div><div class="menus_item"><a class="site-page" href="/friends"><i class="fa-fw fas fa-address-book"></i><span> Friends</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">小波的博客</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 主页</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> Link</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 关于我</span></a></div><div class="menus_item"><a class="site-page" href="/about/"><i class="fa-fw fas fa-heart"></i><span> 工具箱</span></a></div><div class="menus_item"><a class="site-page" href="/friends"><i class="fa-fw fas fa-address-book"></i><span> Friends</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">无题</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-04-07T07:19:50.767Z" title="发表于 2021-04-07 15:19:50">2021-04-07</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-10-24T14:16:57.630Z" title="更新于 2021-10-24 22:16:57">2021-10-24</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">1.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>5分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h2 id="Lombok的使用-转载"><a href="#Lombok的使用-转载" class="headerlink" title="Lombok的使用(转载)"></a>Lombok的使用(转载)</h2><p>我是莫提 <a href="javascript:void(0);">我是莫提</a> <em>8月17日</em></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://mmbiz.qpic.cn/sz_mmbiz_png/XMiaVKe3CRtgB6LODnJm5iaDZb98MJovv1soyxpcib9bLSnAzFVMNeFBJGYIZI090r985RfMgH309OtJAcLicen66Q/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" alt="img"></p>
<hr>
<p><strong>Lombok是什么东西？</strong></p>
<p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20210407152027.webp" alt="img"></p>
<p>Lombok 是一个很牛批的插件（本质是个 Java 库），项目里一旦引入了 Lombok 神器之后，只要程序中使用相关注解，那么你项目中所有诸如：对象的构造函数、 <code>equals()</code>方法，属性的 <code>get()/set() </code>方法等等，这些没有技术含量的代码统统都不用写了，Lombok 帮你搞定一切，全部帮你自动生成！</p>
<hr>
<h2 id="怎样使用-Lombok？"><a href="#怎样使用-Lombok？" class="headerlink" title="怎样使用 Lombok？"></a><strong>怎样使用 Lombok？</strong></h2><h4 id="1、IDEA-下载插件"><a href="#1、IDEA-下载插件" class="headerlink" title="1、IDEA 下载插件"></a><strong>1、IDEA 下载插件</strong></h4><p><img src= "/img/loading.gif" data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20210407152021.webp" alt="img"></p>
<h4 id="2、引入依赖"><a href="#2、引入依赖" class="headerlink" title="2、引入依赖"></a><strong>2、引入依赖</strong></h4><p>在创建 project 是选用 maven 创建，在 pom.xml 中导入 lombok 的依赖即可，代码如下</p>
<figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">dependencies</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">dependency</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">groupId</span>&gt;</span>org.projectlombok<span class="tag">&lt;/<span class="name">groupId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">artifactId</span>&gt;</span>lombok<span class="tag">&lt;/<span class="name">artifactId</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">version</span>&gt;</span>1.18.16<span class="tag">&lt;/<span class="name">version</span>&gt;</span></span><br><span class="line">        <span class="tag">&lt;<span class="name">scope</span>&gt;</span>provided<span class="tag">&lt;/<span class="name">scope</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">dependency</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">dependencies</span>&gt;</span></span><br></pre></td></tr></table></figure>

<hr>
<h2 id="常用的注解"><a href="#常用的注解" class="headerlink" title="常用的注解"></a><strong>常用的注解</strong></h2><h3 id="1、-Data"><a href="#1、-Data" class="headerlink" title="1、@Data"></a><strong>1、<code>@Data</code></strong></h3><p>作用于类上，是以下注解的集合：<code>@ToString @EqualsAndHashCode @Getter @Setter @RequiredArgsConstructor</code>，当类的属性中没有必须属性（即使用 <code>final</code> 关键字声明的属性），那么会生成一个无参构造器。否则生成一个由所有被 <code>final</code> 关键字（或者将标记为@NoNull的属性生成一个构造器 ）声明属性的有参构造函数。</p>
<h5 id="没有-final-声明的属性"><a href="#没有-final-声明的属性" class="headerlink" title="没有 final 声明的属性"></a>没有 <code>final</code> 声明的属性</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Date birthday;</span><br><span class="line">&#125;</span><br><span class="line">====================================</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">    Student student = <span class="keyword">new</span> Student();</span><br><span class="line">    student.setId(<span class="string">&quot;20200202&quot;</span>);</span><br><span class="line">    student.setName(<span class="string">&quot;莫提&quot;</span>);</span><br><span class="line">    student.setBirthday(<span class="keyword">new</span> Date());</span><br><span class="line">    System.out.println(student);</span><br><span class="line"><span class="comment">//...</span></span><br></pre></td></tr></table></figure>

<h5 id="有-final-声明的属性"><a href="#有-final-声明的属性" class="headerlink" title="有 final 声明的属性"></a>有 <code>final</code> 声明的属性</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String id;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Date birthday;</span><br><span class="line">&#125;</span><br><span class="line">====================================</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">    Student student = <span class="keyword">new</span> Student(<span class="string">&quot;莫提&quot;</span>);</span><br><span class="line">    student.setId(<span class="string">&quot;20200202&quot;</span>);</span><br><span class="line">    student.setBirthday(<span class="keyword">new</span> Date());</span><br><span class="line">    System.out.println(student);</span><br><span class="line"><span class="comment">//...</span></span><br></pre></td></tr></table></figure>

<h3 id="2、-Getter和-Setter"><a href="#2、-Getter和-Setter" class="headerlink" title="2、@Getter和@Setter"></a><strong>2、<code>@Getter和@Setter</code></strong></h3><p>为属性生成对应的 <code>get()</code>和<code>set() </code>,声明在类上的时候为所有属性生成对应方法，声明在某个属性的时候，为这个属性生成对应方法。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Getter</span></span><br><span class="line"><span class="meta">@Setter</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Date birthday;</span><br><span class="line">&#125;</span><br><span class="line">====================================</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">    Student student = <span class="keyword">new</span> Student();</span><br><span class="line">    student.setId(<span class="string">&quot;20200202&quot;</span>);</span><br><span class="line">    student.setName(<span class="string">&quot;莫提&quot;</span>);</span><br><span class="line">    student.setBirthday(<span class="keyword">new</span> Date());</span><br><span class="line"><span class="comment">//...</span></span><br></pre></td></tr></table></figure>

<h3 id="3、-Builder"><a href="#3、-Builder" class="headerlink" title="3、@Builder"></a><strong>3、<code>@Builder</code></strong></h3><p>对象的创建即可使用 链式表达 的方式一行代码完成， 看到这里，如果你学过设计模式中的 “建造者模式” 的话，一定能猜到 <code>@Builder</code>注解就是一个典型的“建造者模式”的实现案例！</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Builder</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Date birthday;</span><br><span class="line">&#125;</span><br><span class="line">====================================</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">Student student = Student.builder().id(<span class="string">&quot;1&quot;</span>).name(<span class="string">&quot;莫提&quot;</span>).birthday(<span class="keyword">new</span> Date()).build();</span><br><span class="line"><span class="comment">//...</span></span><br></pre></td></tr></table></figure>

<h3 id="3、构造函数注解"><a href="#3、构造函数注解" class="headerlink" title="3、构造函数注解"></a><strong>3、构造函数注解</strong></h3><ol>
<li>@AllArgsConstructor（全参构造）</li>
<li>@NoArgsConstructor （空参构造）</li>
<li>@RequiredArgsConstructor （部分参数构造，参数使用<code>final</code>关键字声明）</li>
</ol>
<p>注意这里 @RequiredArgsConstructor 和 @NoArgsConstructor 不能同时出现，因为当一个属性被final关键字声明后，创建对象的时候一定要给这个属性传参，所以可以理解这两个注解是冲突的。</p>
<h5 id="空参构造和全参构造"><a href="#空参构造和全参构造" class="headerlink" title="空参构造和全参构造"></a>空参构造和全参构造</h5><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@NoArgsConstructor</span></span><br><span class="line"><span class="meta">@AllArgsConstructor</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> String id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Date birthday;</span><br><span class="line">&#125;</span><br><span class="line">====================================</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">Student student1 = <span class="keyword">new</span> Student();</span><br><span class="line">Student student2 = <span class="keyword">new</span> Student(<span class="string">&quot;1&quot;</span>,<span class="string">&quot;moti&quot;</span>,<span class="keyword">new</span> Date());</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">部分参数构造和全参构造<span class="meta">@RequiredArgsConstructor</span></span><br><span class="line"><span class="meta">@AllArgsConstructor</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Student</span> </span>&#123;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> String id;</span><br><span class="line">    <span class="keyword">private</span> String name;</span><br><span class="line">    <span class="keyword">private</span> Date birthday;</span><br><span class="line">&#125;</span><br><span class="line">====================================</span><br><span class="line"><span class="comment">//...</span></span><br><span class="line">Student student1 = <span class="keyword">new</span> Student(<span class="string">&quot;1&quot;</span>);</span><br><span class="line">Student student2 = <span class="keyword">new</span> Student(<span class="string">&quot;1&quot;</span>,<span class="string">&quot;moti&quot;</span>,<span class="keyword">new</span> Date());</span><br><span class="line"><span class="comment">//...</span></span><br></pre></td></tr></table></figure>

<h3 id="4、-NonNull"><a href="#4、-NonNull" class="headerlink" title="4、@NonNull"></a><strong>4、<code>@NonNull</code></strong></h3><p>Lombok的 <code>@NonNull</code>注解可以自动帮我们避免空指针判断。主要作用于成员变量和参数中，标识不能为空，否则抛出空指针异常。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">testNonNull</span><span class="params">(<span class="meta">@NonNull</span> String input)</span></span>&#123;</span><br><span class="line">    System.out.println(input);</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line">    testNonNull(<span class="keyword">null</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>运行main方法之后，控制台报错。</p>
<p><img src= "/img/loading.gif" data-lazy-src="https://mmbiz.qpic.cn/sz_mmbiz_png/XMiaVKe3CRtgB6LODnJm5iaDZb98MJovv1Ya7rHNFh3kQbJEdME9ND7F48ztrIlnBzIjUYOQWFN9icRaOKCLWDUwg/640?wx_fmt=png&tp=webp&wxfrom=5&wx_lazy=1&wx_co=1" alt="img"></p>
<h3 id="5、-Cleanup"><a href="#5、-Cleanup" class="headerlink" title="5、@Cleanup"></a><strong>5、<code>@Cleanup</code></strong></h3><p>自动关闭资源，针对实现了java.io.Closeable接口的对象有效，如：典型的IO流对象，也就是不需要在finally子句里面手动关闭资源了。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testCleanup</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Cleanup</span> BufferedReader br = <span class="keyword">null</span>;</span><br><span class="line">    <span class="meta">@Cleanup</span> FileReader fileReader = <span class="keyword">null</span>;</span><br><span class="line">    <span class="keyword">try</span> &#123;</span><br><span class="line">        fileReader = <span class="keyword">new</span> FileReader(<span class="string">&quot;hehe.txt&quot;</span>);</span><br><span class="line">        br = <span class="keyword">new</span> BufferedReader(fileReader);</span><br><span class="line">        <span class="comment">//中间一些流操作</span></span><br><span class="line">    &#125; <span class="keyword">catch</span> (FileNotFoundException e) &#123;</span><br><span class="line">        e.printStackTrace();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<h3 id="6、-SneakyThrows"><a href="#6、-SneakyThrows" class="headerlink" title="6、@SneakyThrows"></a><strong>6、<code>@SneakyThrows</code></strong></h3><p>可以对受检异常进行捕捉并抛出</p>
<p>对上面的程序进行简化</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@SneakyThrows</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">testSneakyThrows</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="meta">@Cleanup</span> BufferedReader br = <span class="keyword">null</span>;</span><br><span class="line">    <span class="meta">@Cleanup</span> FileReader fileReader = <span class="keyword">null</span>;</span><br><span class="line">        fileReader = <span class="keyword">new</span> FileReader(<span class="string">&quot;hehe.txt&quot;</span>);</span><br><span class="line">        br = <span class="keyword">new</span> BufferedReader(fileReader);</span><br><span class="line">        <span class="comment">//中间一些流操作</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<hr>
<h2 id="注解表"><a href="#注解表" class="headerlink" title="注解表"></a><strong>注解表</strong></h2><table>
<thead>
<tr>
<th>注解名</th>
<th>作用</th>
</tr>
</thead>
<tbody><tr>
<td>@Setter</td>
<td>生成 setter 方法,final 变量不包含</td>
</tr>
<tr>
<td>@Getter</td>
<td>生成 getter 方法,final 变量不包含</td>
</tr>
<tr>
<td>@NoArgsConstructor</td>
<td>生成空参构造器</td>
</tr>
<tr>
<td>@AllArgsConstructor</td>
<td>生成全部参数构造器</td>
</tr>
<tr>
<td>@RequiredArgsConstructor</td>
<td>将标记为 @NoNull 的属性生成一个构造器</td>
</tr>
<tr>
<td>@ToString</td>
<td>生成所有属性的 toString() 方法</td>
</tr>
<tr>
<td>@EqualsAndHashCode</td>
<td>生成 equals() 方法和 hashCode 方法</td>
</tr>
<tr>
<td>@Data(常用)</td>
<td>@Data 直接修饰 POJO or beans， </br>@Data=@Setter+@Getter+@EqualsAndHashCode + 空惨构造器+ toString</td>
</tr>
<tr>
<td>@Builder</td>
<td>构造 Builder 模式的结构。通过内部类 Builder() 进行构建对象。</td>
</tr>
<tr>
<td>@Value</td>
<td>与 @Data 相对应的 @Value，主要区别是如果变量不加 @NonFinal ，@Value 会给所有的弄成 final 修饰的。当然如果是 final 修饰的话，就没有 set 方法了。</td>
</tr>
<tr>
<td>@Synchronized</td>
<td>同步方法</td>
</tr>
<tr>
<td>@Cleanup</td>
<td>自动调用 close 方法关闭资源</td>
</tr>
<tr>
<td>@SneakyThrows</td>
<td>可以对受检异常进行捕捉并抛出</td>
</tr>
<tr>
<td>@Log4j</td>
<td>注解在类上；为类提供一个属性名为 log 的 log4j 日志对像</td>
</tr>
<tr>
<td>@Slf4j</td>
<td>同 @Log4j</td>
</tr>
</tbody></table>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">Steve</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="https://steve6636.gitee.io/2021/04/07/Lombok%20%E7%9A%84%E4%BD%BF%E7%94%A8_20210320/">https://steve6636.gitee.io/2021/04/07/Lombok%20%E7%9A%84%E4%BD%BF%E7%94%A8_20210320/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://steve6636.gitee.io" target="_blank">小波的博客</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/social-share.js/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/social-share.js/dist/js/social-share.min.js" defer></script></div></div><div class="post-reward"><div class="reward-button button--animated"><i class="fas fa-qrcode"></i> 打赏</div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/wechat.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="/img/wechat.jpg" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="/img/alipay.jpg" target="_blank"><img class="post-qr-code-img" data-lazy-src="/img/alipay.jpg" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/05/10/Windows-Terminal-install-settings/"><img class="prev-cover" data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20210929231042.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Windows Terminal安装与美化</div></div></a></div><div class="next-post pull-right"><a href="/2021/04/01/%E6%A0%B9%E6%8D%AE%E7%94%A8%E6%88%B7%E8%BE%93%E5%85%A5%E6%97%A5%E6%9C%9F%E8%AE%A1%E7%AE%97%E5%A4%A9%E6%95%B0/"><img class="next-cover" data-lazy-src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">根据用户输入日期计算天数</div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="card-info-avatar is-center"><img class="avatar-img" data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20210327175316.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/><div class="author-info__name">Steve</div><div class="author-info__description">路漫漫其修远兮，吾将上下而求索</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">26</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">11</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">9</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/forkiller"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/forkiller" target="_blank" title="Github"><i class="fab fa-github"></i></a><a class="social-icon" href="mailto:1518109600@qq.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content">冷灯看剑，剑上几番功名？炉香无须计苍生，纵一川烟逝，万丈云埋，孤阳还照古陵</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#Lombok%E7%9A%84%E4%BD%BF%E7%94%A8-%E8%BD%AC%E8%BD%BD"><span class="toc-text">Lombok的使用(转载)</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%8E%E6%A0%B7%E4%BD%BF%E7%94%A8-Lombok%EF%BC%9F"><span class="toc-text">怎样使用 Lombok？</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1%E3%80%81IDEA-%E4%B8%8B%E8%BD%BD%E6%8F%92%E4%BB%B6"><span class="toc-text">1、IDEA 下载插件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2%E3%80%81%E5%BC%95%E5%85%A5%E4%BE%9D%E8%B5%96"><span class="toc-text">2、引入依赖</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%B8%B8%E7%94%A8%E7%9A%84%E6%B3%A8%E8%A7%A3"><span class="toc-text">常用的注解</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1%E3%80%81-Data"><span class="toc-text">1、@Data</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%B2%A1%E6%9C%89-final-%E5%A3%B0%E6%98%8E%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="toc-text">没有 final 声明的属性</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#%E6%9C%89-final-%E5%A3%B0%E6%98%8E%E7%9A%84%E5%B1%9E%E6%80%A7"><span class="toc-text">有 final 声明的属性</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2%E3%80%81-Getter%E5%92%8C-Setter"><span class="toc-text">2、@Getter和@Setter</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81-Builder"><span class="toc-text">3、@Builder</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3%E3%80%81%E6%9E%84%E9%80%A0%E5%87%BD%E6%95%B0%E6%B3%A8%E8%A7%A3"><span class="toc-text">3、构造函数注解</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%A9%BA%E5%8F%82%E6%9E%84%E9%80%A0%E5%92%8C%E5%85%A8%E5%8F%82%E6%9E%84%E9%80%A0"><span class="toc-text">空参构造和全参构造</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4%E3%80%81-NonNull"><span class="toc-text">4、@NonNull</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5%E3%80%81-Cleanup"><span class="toc-text">5、@Cleanup</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6%E3%80%81-SneakyThrows"><span class="toc-text">6、@SneakyThrows</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B3%A8%E8%A7%A3%E8%A1%A8"><span class="toc-text">注解表</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2022/03/06/Mysql%E7%9A%84%E4%BC%98%E5%8C%96-%E8%87%AA%E6%88%91%E6%8F%8F%E8%BF%B0/" title="MySQL 的优化.md"><img data-lazy-src="https://img2.baidu.com/it/u=1814268193,3619863984&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=JPEG?w=632&amp;h=500" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL 的优化.md"/></a><div class="content"><a class="title" href="/2022/03/06/Mysql%E7%9A%84%E4%BC%98%E5%8C%96-%E8%87%AA%E6%88%91%E6%8F%8F%E8%BF%B0/" title="MySQL 的优化.md">MySQL 的优化.md</a><time datetime="2022-03-06T14:54:18.000Z" title="发表于 2022-03-06 22:54:18">2022-03-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/06/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93%E5%A4%87%E4%BB%BD%E5%91%BD%E4%BB%A4-20210722/" title="MySQL 数据库备份命令.md"><img data-lazy-src="https://img2.baidu.com/it/u=1814268193,3619863984&amp;fm=253&amp;fmt=auto&amp;app=138&amp;f=JPEG?w=632&amp;h=500" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="MySQL 数据库备份命令.md"/></a><div class="content"><a class="title" href="/2022/03/06/MySQL%E6%95%B0%E6%8D%AE%E5%BA%93%E5%A4%87%E4%BB%BD%E5%91%BD%E4%BB%A4-20210722/" title="MySQL 数据库备份命令.md">MySQL 数据库备份命令.md</a><time datetime="2022-03-06T14:47:18.000Z" title="发表于 2022-03-06 22:47:18">2022-03-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/06/Git-study/" title="git 笔记.md"><img data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20220306225241.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="git 笔记.md"/></a><div class="content"><a class="title" href="/2022/03/06/Git-study/" title="git 笔记.md">git 笔记.md</a><time datetime="2022-03-06T14:47:18.000Z" title="发表于 2022-03-06 22:47:18">2022-03-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/06/Junit&amp;jdk8%E6%96%B0%E7%89%B9%E6%80%A7/" title="jdk8 新特性.md"><img data-lazy-src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.05sun.com%2Fup%2F2006%2F2020611101156542640.png&amp;refer=http%3A%2F%2Fimg.05sun.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1649170568&amp;t=1d3529a6cb00dac37673cce4473d9a89" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="jdk8 新特性.md"/></a><div class="content"><a class="title" href="/2022/03/06/Junit&amp;jdk8%E6%96%B0%E7%89%B9%E6%80%A7/" title="jdk8 新特性.md">jdk8 新特性.md</a><time datetime="2022-03-06T14:47:18.000Z" title="发表于 2022-03-06 22:47:18">2022-03-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2022/03/06/Docker%20%E7%AC%94%E8%AE%B0_20210404/" title="Docker 笔记.md"><img data-lazy-src="https://gitee.com/forkiller/picture/raw/master/img/20220306223850.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Docker 笔记.md"/></a><div class="content"><a class="title" href="/2022/03/06/Docker%20%E7%AC%94%E8%AE%B0_20210404/" title="Docker 笔记.md">Docker 笔记.md</a><time datetime="2022-03-06T14:29:58.000Z" title="发表于 2022-03-06 22:29:58">2022-03-06</time></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/img/default.jpg')"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2022 By Steve</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="font-plus" type="button" title="放大字体"><i class="fas fa-plus"></i></button><button id="font-minus" type="button" title="缩小字体"><i class="fas fa-minus"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div id="local-search"><div class="search-dialog"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div></div><hr/><div id="local-search-results"></div><span class="search-close-button"><i class="fas fa-times"></i></span></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"></div><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = true;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/click-heart.min.js" async="async" mobile="true"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = [
  'title',
  '#config-diff',
  '#body-wrap',
  '#rightside-config-hide',
  '#rightside-config-show',
  '.js-pjax'
]

if (false) {
  pjaxSelectors.unshift('meta[property="og:image"]', 'meta[property="og:title"]', 'meta[property="og:url"]')
}

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  if (typeof gtag === 'function') {
    gtag('config', '', {'page_path': window.location.pathname});
  }

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // Analytics
  if (false) {
    MtaH5.pgv()
  }

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()

  typeof preloader === 'object' && preloader.endLoading()
})


document.addEventListener('pjax:send', function () {
  typeof preloader === 'object' && preloader.initLoading()
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div></body></html>